/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.vale.entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Gabriel Bran gbran.u@gmail.com
 */
@Entity
@Table(name = "contact_site")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ContactSite.findAll", query = "SELECT c FROM ContactSite c"),
    @NamedQuery(name = "ContactSite.findNextId", query = "SELECT COUNT(c) FROM ContactSite c WHERE c.contactSitePK.idsite = :idsite"),
    @NamedQuery(name = "ContactSite.findByIdsite", query = "SELECT c FROM ContactSite c WHERE c.contactSitePK.idsite = :idsite"),
    @NamedQuery(name = "ContactSite.findByIdcontact", query = "SELECT c FROM ContactSite c WHERE c.contactSitePK.idcontact = :idcontact"),
    @NamedQuery(name = "ContactSite.findByFullname", query = "SELECT c FROM ContactSite c WHERE c.fullname = :fullname"),
    @NamedQuery(name = "ContactSite.findByMobile", query = "SELECT c FROM ContactSite c WHERE c.mobile = :mobile"),
    @NamedQuery(name = "ContactSite.findByEmail", query = "SELECT c FROM ContactSite c WHERE c.email = :email")})
public class ContactSite implements Serializable {

    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ContactSitePK contactSitePK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(name = "fullname")
    private String fullname;
    @Size(max = 15)
    @Column(name = "mobile")
    private String mobile;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Size(max = 50)
    @Column(name = "email")
    private String email;
    @JoinColumn(name = "codcontacttype", referencedColumnName = "codcontacttype")
    @ManyToOne(optional = false)
    private ContactType codcontacttype;
    @JoinColumn(name = "idsite", referencedColumnName = "idsite", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Site site;

    public ContactSite() {
    }

    public ContactSite(ContactSitePK contactSitePK) {
        this.contactSitePK = contactSitePK;
    }

    public ContactSite(ContactSitePK contactSitePK, String fullname) {
        this.contactSitePK = contactSitePK;
        this.fullname = fullname;
    }

    public ContactSite(String idsite, int idcontact) {
        this.contactSitePK = new ContactSitePK(idsite, idcontact);
    }

    public ContactSitePK getContactSitePK() {
        return contactSitePK;
    }

    public void setContactSitePK(ContactSitePK contactSitePK) {
        this.contactSitePK = contactSitePK;
    }

    public String getFullname() {
        return fullname;
    }

    public void setFullname(String fullname) {
        this.fullname = fullname;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public ContactType getCodcontacttype() {
        return codcontacttype;
    }

    public void setCodcontacttype(ContactType codcontacttype) {
        this.codcontacttype = codcontacttype;
    }

    public Site getSite() {
        return site;
    }

    public void setSite(Site site) {
        this.site = site;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (contactSitePK != null ? contactSitePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ContactSite)) {
            return false;
        }
        ContactSite other = (ContactSite) object;
        if ((this.contactSitePK == null && other.contactSitePK != null) || (this.contactSitePK != null && !this.contactSitePK.equals(other.contactSitePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.vale.entity.ContactSite[ contactSitePK=" + contactSitePK + " ]";
    }

}
